<template>
<x-dialog v-model="show"  >
	<div class="weui-dialog__hd showContent"> 
        <strong class="weui-dialog__title">第一次访问需要绑定账户</strong>
     </div>
     <div class="weui-dialog__bda weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">账号</label>
            </div>
            <div class="weui-cell__bd">
                <input type="text" class=" weui-input" v-model="user.account"  v-ab-validate="{'required':true}" desc="请输入账户信息"/>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label class="weui-label">密码</label>
            </div>
            <div class="weui-cell__bd">
                <input type="password" class=" weui-input" v-model="user.password" v-ab-validate="{'required':true}" desc="用户名"/>
            </div>
        </div>
     </div>
      <div class="weui-dialog__ft">
        <a class="weui-dialog__btn weui-dialog__btn_default" v-on:click="bindUser()">绑定</a>
      </div>
  </x-dialog>
</template>
<script>
export default {
  created:function(){
	  this.wxLogin();
  },
  methods: {
     wxLogin() {
    	var defer = this.baseService.postForm(this.__ctx + "/org/wx/login",{code:this.abTools.getParam("code")});
    	defer.then((data)=>{
    		if(data.isOk){
	    		this.$router.push('/');
	    		return;
    		}
    		if(data.code === "-1"){
    			this.show = true;
    			return;
    		}
    		alert(data.msg);
    	})
    },
    bindUser(){
    	if(!this.user.account || !this.user.password){
    		this.abTools.toast("请完善登录信息！","warn");
    		return ;
    	}
    	var post = this.baseService.postForm(this.__ctx+"/org/wx/bindUser",this.user);
 		this.abTools.getResultData(post,()=>{
 			this.show = false;
 			this.abTools.toast("绑定成功","success");
 			this.$router.push('/');
 		},"toast")
    },
  },
  name: 'Home',
  data () {
    return {
      show: false,
      user:{},
    }
  }
}
</script>
<style>
 .weui-dialog__bda {
  padding: 0.8em 1.6em 0.8em;
  min-height: 40px;
  font-size: 15px;
  line-height: 1.3;
  word-wrap: break-word;
  word-break: break-all;
  color: #999999;
}

</style>